package com.cy.pj.sys.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.cy.pj.common.pojo.JsonResult;
import com.cy.pj.common.pojo.PageObject;
import com.cy.pj.sys.pojo.SysRole;
import com.cy.pj.sys.service.SysRoleService;

@RestController
@RequestMapping("/role/")
public class SysRoleController {

	@Autowired
	private SysRoleService sysRoleService;
	
	
	//查询所有角色
	@RequestMapping("doFindPageObjects")
	public JsonResult doFindObject(String name,Integer pageCurrent) {
		PageObject<SysRole> object = sysRoleService.findPageObject(name, pageCurrent);
		return new JsonResult(object);
	}
	
	//删除角色
	@RequestMapping("doDeleteObject")
	public JsonResult doDeleteObject(Integer id) {
		sysRoleService.deleteObejct(id);
		return new JsonResult("删除成功");
	}
	
	//新增角色
	@RequestMapping("doSaveObject")
	public JsonResult doInsertObject(SysRole entity,Integer[] menuIds) {
		sysRoleService.saveObject(entity, menuIds);
		return new JsonResult("新增成功");
	}
	
	//点击修改后查询选中的角色信息
	@RequestMapping("doFindObjectById")
	public JsonResult doFindObjectById(Integer id) {
		return new JsonResult(sysRoleService.findById(id));
	}
	
	//修改角色信息
	@RequestMapping("doUpdateObject")
	public JsonResult doUpdateObject(SysRole entity,Integer[] menuIds) {
		sysRoleService.updateObject(entity, menuIds);
		return new JsonResult("修改成功");
	}
	
	//此处为在用户管理页面时，添加新用户时查询所有的角色信息出来供用户选择
	@RequestMapping("doFindRoles")
	public JsonResult doFindRoles() {
		return new JsonResult(sysRoleService.findObject());
	}
}
